package com.byron.pss.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * 对所有的访问都进行拦截，将编码方式在这里统一设置
 * @author Byron
 *
 */
public class EncodingFilter implements Filter {

	// 请求编码设置
	private String RequestEncoding;
	// 响应编码设置
	private String ResponseEncoding;

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		RequestEncoding = filterConfig.getInitParameter("RequestEncoding");
		ResponseEncoding = filterConfig.getInitParameter("ResponseEncoding");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		request.setCharacterEncoding(RequestEncoding);
		response.setCharacterEncoding(ResponseEncoding);
		//放行
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {

	}

}
